/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { ISearchWorker } from './worker/searchWorkerIpc';
import { RawSearchWorker } from 'vs/workbench/services/search/node/worker/searchWorker';

export interface ITextSearchWorkerProvider {
	getWorkers(): ISearchWorker[];
}

export class TextSearchWorkerProvider implements ITextSearchWorkerProvider {
	private workers: ISearchWorker[] = [];

	getWorkers(): ISearchWorker[] {
		const numWorkers = 1;//os.cpus().length;
		while (this.workers.length < numWorkers) {
			this.createWorker();
		}

		return this.workers;
	}

	private createWorker(): void {
		// let client = new Client(
		// 	uri.parse(require.toUrl('bootstrap')).fsPath,
		// 	{
		// 		serverName: 'Search Worker ' + this.workers.length,
		// 		args: ['--type=searchWorker'],
		// 		timeout: 30 * 1000,
		// 		env: {
		// 			AMD_ENTRYPOINT: 'vs/workbench/services/search/node/worker/searchWorkerApp',
		// 			PIPE_LOGGING: 'true',
		// 			VERBOSE_LOGGING: false//process.env.VERBOSE_LOGGING
		// 		},
		// 		useQueue: true
		// 	});

		// const channel = ipc.getNextTickChannel(client.getChannel<ISearchWorkerChannel>('searchWorker'));
		// const channelClient = new SearchWorkerChannelClient(channel);

		this.workers.push(new RawSearchWorker());
	}
}